import 'package:get/get.dart';
import 'package:jm_flutter/jm_flutter.dart';

///首次使用
bool get isFirstUse => Storage.read("isFirstUse", defVal: true);

setFirstUse() => Storage.write("isFirstUse", false);

AppController? _controller;

AppController? get currentApp {
  if (_controller == null) {
    loge("tag", "currentApp为空");
  }
  return _controller;
}

setCurrentApp(AppController controller) {
  _controller = controller;
}

AppController get findApp {
  try {
    return Get.find<AppController>();
  } catch (e) {
    logd("AppController", "未初始化AppController");
    return Get.put(AppController(), permanent: true);
  }
}

class AppController extends GetxController {
  final tag = "AppController";

  var isConnected = false.obs;

  @override
  void onInit() {
    // TODO: implement onInit
    super.onInit();

    logd(tag, "onInit");

    ever(isConnected, (value) {
      logd(tag, "isConnected改变:" + value.toString());
    });

    //Timer.periodic(const Duration(seconds: 1), (timer) async {});
  }
}
